home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 May
/
EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso
/
softwareupdate
/
system
/
amigados
/
advancedroutines
/
example5.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-10-10
|
7KB
|
233 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) Amiga C Club (ACC) */
/* -------------------------- ------------------ */
/* */
/* Manual: AmigaDOS Amiga C Club */
/* Chapter: Advanced Routines Tulevagen 22 */
/* File: Example5.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 93-03-17 */
/* Version: 1.2 */
/* */
/* Copyright 1993, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example demonstrates how to use the Info() function */
/* to get some information about a disk. We will, among many */
/* things, check if the disk is write protected or not, what */
/* type of disk it is etc... In this example we examine the */
/* disk in "df0:". */
/* */
/* This example can be used with all versions of the dos */
/* library. */
/* Include the dos library definitions: */
#include <dos/dos.h>
/* Include memory definitions: (MEMF_ANY...) */
#include <exec/memory.h>
/* Now we include the necessary function prototype files: */
#include <clib/dos_protos.h> /* General dos functions... */
#include <clib/exec_protos.h> /* System functions... */
#include <stdio.h> /* Std functions [printf()...] */
#include <stdlib.h> /* Std functions [exit()...] */
/* The disk we want to examine: */
#define DISK_STR "df0:"
/* Set name and version number: */
UBYTE *version = "$VER: AmigaDOS/Advanced Routines/Example5 1.2";
/* Declared our own functions: */
int main( int argc, char *argv[] );
/* Now the "real" program code starts: */
int main( int argc, char *argv[] )
{
/* A "BCPL" pointer to our lock: */
BPTR my_lock;
/* A pointer to our info data block: */
struct InfoData *my_info_data;
/* AmigaDOS boolean check variable: */
LONG ok;
/* Allocate enough memory to store an InfoData structure in. Since */
/* Info() wants the memoryblock to be "longword-aligned" we have */
/* to allocate it ourself. (A longword-aligned data block starts */
/* on a complete 32-bit, longword, address). If we simply declare */
/* the structure in the C code it might happen that it starts in */
/* the middle of a longword address, and this could crash the */
/* system! */
my_info_data = (struct InfoData *)
AllocMem( sizeof( struct InfoData ), MEMF_ANY );
/* Have we successfully allocated the memory? */
if( !my_info_data )
{
/* Not enough memory! Inform the user and quit: */
printf( "Could not allocate enough memory!\n" );
/* Exit with an error code: */
exit( 20 );
}
/* Lock the disk, or any file on that disk, we want to examine: */
/* (Since we only want to examine the disk, read some stuff, we */
/* only have to put a shared lock on it.) */
my_lock = Lock( DISK_STR, SHARED_LOCK );
/* Have we successfully locked the disk? */
if( !my_lock )
{
/* Could not lock the disk! */
/* Inform the user: */
printf( "Could not lock the disk \"%s\"!\n", DISK_STR );
/* Free the previously allocated memory: */
FreeMem( my_info_data, sizeof( struct InfoData ) );
/* Exit with an error code: */
exit( 21 );
}
/* Once we have allocated some memory for the info data structure */
/* and have locked the disk we want to examine, we may call Info(): */
ok = Info( my_lock, my_info_data );
/* Have we successfully collected the data? */
if( !ok )
{
/* Problems, we could not examine the disk! */
/* Inform the user: */
printf( "Could not examine the disk \"%s\"!\n", DISK_STR );
/* Unlock the disk: */
UnLock( my_lock );
/* Free the previously allocated memory: */
FreeMem( (APTR) my_info_data, sizeof( struct InfoData ) );
/* Exit with an error code: */
exit( 22 );
}
/* We can now examine the disk: (Here is a small */
/* demonstration on what you can do.) */
printf( "\n\nHere is some information about the disk in drive %s\n\n",
DISK_STR );
/* The unit number: */
printf( "Disk unit number: %d\n", my_info_data->id_UnitNumber );
/* Disk Status: */
/* Is the disk write protected? */
if( my_info_data->id_DiskState == ID_WRITE_PROTECTED )
printf( "The disk is Write Protected!\n" );
/* Is the disk being validated? */
if( my_info_data->id_DiskState == ID_VALIDATING )
printf( "The disk is being validated!\n" );
/* Is the disk validated but not write protected? */
if( my_info_data->id_DiskState == ID_VALIDATED )
printf( "The disk is Not (Write) Protected!\n" );
/* Disk Types: */
switch( my_info_data->id_DiskType )
{
case ID_NO_DISK_PRESENT:
printf( "No disk present\n" );
break;
case ID_UNREADABLE_DISK:
printf( "Unreadable disk\n" );
break;
case ID_DOS_DISK:
printf( "DOS number 0 (Nomal) disk\n" );
break;
case ID_FFS_DISK:
printf( "DOS number 1 (Fast FileSystem) disk\n" );
break;
case ID_INTER_DOS_DISK:
printf( "DOS number 3 (Int. Normal) disk\n" );
break;
case ID_INTER_FFS_DISK:
printf( "DOS number 4 (Int. Fast FileSystem) disk\n" );
break;
case ID_NOT_REALLY_DOS:
printf( "Not a dos disk\n" );
break;
case ID_KICKSTART_DISK:
printf( "kickstart disk\n" );
break;
case ID_MSDOS_DISK:
printf( "MS DOS disk\n" );
break;
}
/* If the disk is in use or not: */
if( my_info_data->id_InUse )
printf( "The disk is in use.\n" );
else
printf( "The disk is not in use.\n" );
/* Print some disk size data: */
printf( "Number of blocks on disk: %5d\n",
my_info_data->id_NumBlocks );
printf( "Number of blocks used: %5d\n",
my_info_data->id_NumBlocksUsed );
printf( "Number of bytes per block: %5d\n\n",
my_info_data->id_BytesPerBlock );
/* Unlock the disk: */
UnLock( my_lock );
/* Free the previously allocated memory: */
FreeMem( my_info_data, sizeof( struct InfoData ) );
/* The End (0 = success): */
exit( 0 );
}